package com.yix.study.tec.entity;

public class AbstractFactoryTest {
    public static void main(String[] args) {
        try {
            Product a;
            AbstractFactory af;
            af = (AbstractFactory) ReadXML1.getObject();
            a = af.newProduct();
            a.show();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}

//抽象产品：提供产品接口
interface Product{
    public void show();
}

class ConcreProduct1 implements Product{

    @Override
    public void show() {
        System.out.println("具体产品1显示...");
    }
}

class ConcreProduct2 implements Product{

    @Override
    public void show() {
        System.out.println("具体产品2显示...");
    }
}


//抽象工厂：提供厂品的方法
interface AbstractFactory{
    public Product newProduct();
}

class ConcreFactoty1 implements AbstractFactory{

    @Override
    public Product newProduct() {
        System.out.println("具体工厂1生成-->具体产品1...");
        return new ConcreProduct1();
    }
}
class ConcreFactoty2 implements AbstractFactory{

    @Override
    public Product newProduct() {
        System.out.println("具体工厂2生成-->具体产品2...");
        return new ConcreProduct2();
    }
}
